#ifndef __GLESProgram_H__
#define __GLESProgram_H__

#include "HighLevelGpuProgram.h"

namespace PVM
{
	class GLSLESProgram : public HighLevelGpuProgram
	{
	public:
		class CmdOptimisation : public ParamCommand
		{
		public:
			std::string doGet(const void* target) const;
			void doSet(void* target, const std::string& val);
		};
		
		class CmdPreprocessorDefines : public ParamCommand
		{
		public:
			std::string doGet(const void* target) const;
			void doSet(void* target, const std::string& val);
		};
		
		GLSLESProgram(ResourceManager* creator,
					  const std::string& name, ResourceHandle handle,
					  const std::string& group, bool isManual, ManualResourceLoader* loader);
		~GLSLESProgram();
		
		const GLuint getGLHandle() const {return mGLHandle;}
		void attachToProgramObject(const GLuint programObject);
		void detachFromProgramObject(const GLuint programObject);
		
		bool getPassTransformStates(void) const;
		bool getPassSurfaceAndLightStates(void) const;
		bool getPassFogStates(void) const;
		
		void setPreprocessorDefines(const std::string& defines) {mPreprocessorDefines = defines;}
		const std::string& getPreprocessorDefines(void) const {return mPreprocessorDefines;}
		
		void setOptimiserEnabled(bool enabled) {mOptimiserEnabled = enabled;}
		bool getOptimiserEnabled(void) const {return mOptimiserEnabled;}
		
		void setIsOptimised(bool flag) {mIsOptimised = flag;}
		bool getIsOptimised(void) {return mIsOptimised;}
		
		const std::string& getLanguage(void) const;
		GpuProgramParametersSharedPtr createParameters(void);
		
		bool compile(const bool checkErrors = false);
		
	protected:
		static CmdPreprocessorDefines msCmdPreprocessorDefines;
		static CmdOptimisation msCmdOptimisation;
		
		void loadFromSource(void);
		void createLowLevelImpl(void);
		void unloadHighLevelImpl(void);
		void unloadImpl(void);
		
		void populateParameterNames(GpuProgramParametersSharedPtr params);
		void buildConstantDefinitions() const;
		
		void checkAndFixInvalidDefaultPrecisionError(std::string& message);
		
	private:
		GLuint mGLHandle;
		GLint mCompiled;
		bool mIsOptimised;
		std::string mPreprocessorDefines;
		bool mOptimiserEnabled;
	};
}

#endif
